package com.timoon.sample.page;

import java.util.Arrays;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.googlecode.wicket.jquery.ui.Options;
import com.timoon.app.resource.css.CSSLocation;
import com.timoon.component.behavior.bootstrap.AbstractBootStrapBehavior;
import com.timoon.component.panel.common.DefaultEmptyPanel;
import com.timoon.page.Page1;
import com.timoon.sample.service.DiscountServiceImpl;
import com.timoon.sample.service.InfoMediumServiceImpl;
import com.timoon.sample.service.RankServiceImpl;
import com.timoon.sample.utils.SystemConfig;
import com.timoon.webcomponent.utility.form.form1.Form1Panel;
import com.timoon.webcomponent.utility.header.Header1Panel;
import com.timoon.webcomponent.utility.helpinfo.CustomerCenter;
import com.timoon.webcomponent.utility.helpinfo.HelpInfoPanel;
import com.timoon.webcomponent.utility.info.Info1Panel;
import com.timoon.webcomponent.utility.info.Info1Service;
import com.timoon.webcomponent.utility.navs.jd.JdNavPanel;
import com.timoon.webcomponent.utility.navs.nav1.Nav1Panel;
import com.timoon.webcomponent.utility.pic.gridsmallpic.GridSmallPicPanel;
import com.timoon.webcomponent.utility.product.carousel.Carousel1Panel;
import com.timoon.webcomponent.utility.product.discount.Discount1Panel;
import com.timoon.webcomponent.utility.product.discount.Discount1Service;
import com.timoon.webcomponent.utility.product.girdpic.GridBigPicPanel;
import com.timoon.webcomponent.utility.product.girdpic.GridBigPicService;
import com.timoon.webcomponent.utility.product.horizontalListPic.HorizontalListPicProductInTabPanel;
import com.timoon.webcomponent.utility.product.linepic.HorizontalList4PicProductPanel;
import com.timoon.webcomponent.utility.product.linepic.HorizontalListPicProductPanel;
import com.timoon.webcomponent.utility.product.rank.RankPanel;
import com.timoon.webcomponent.utility.product.rank.RankService;
import com.timoon.webcomponent.utility.product.sort.sortnav1.InsideNavsPanel;
import com.timoon.webcomponent.utility.product.sort.sortnav1.InsideNavsService;
import com.timoon.webcomponent.utility.product.sort.sortnav2.Sortnav2Panel;
import com.timoon.webcomponent.utility.slide.Slide1Panel;
import com.timoon.webcomponent.utility.slide.Slide1Service;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class HomePage extends WebPage {
	
	public HomePage(PageParameters pageParameters) {
		// TODO Auto-generated constructor stub
		
		renderPanel();
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		//引用bootstrap
		this.add(new AbstractBootStrapBehavior("#ddddddd", "click", new Options()));
		
		//renderLogo();
		
		//renderSearchForm();
		
		//renderShoppingCart();
		
		renderHeader();
		
		//主导航
		renderNav();
		
		//商品分类
		renderSortNav();
		
		renderPicList();
		
		//幻灯片
		renderCarousel();
		
		//报道
		renderInfoReport();
		
		renderDiscount1();
		
		//推荐商品
		renderRecommentProduct();
		
		renderTimeoutProduct();
		
		renderRank();//排行
		
		renderGridPic();//图片grid
		
		renderBigGridProductPic();
		
		renderHelpInfo();
		
		renderCustomerCenter();//服务中心
		
	}

private void renderCustomerCenter() {
		// TODO Auto-generated method stub
		add(new CustomerCenter("wk_customer_center"));
	}

private void renderHelpInfo() {
		// TODO Auto-generated method stub
		add(new HelpInfoPanel("wk_help_list",HelpListPage.class));
	}

	private void renderHeader() {
		// TODO Auto-generated method stub
		add(new Header1Panel("wk_header"));
	}

	private void renderShoppingCart() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_shopping_cart") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new DefaultEmptyPanel(arg0,"购物车");
			}
		});
	}

	private void renderLogo() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_logo") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new DefaultEmptyPanel(arg0,"logo");
			}
		});
	}
	private void renderSearchForm() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_search_form") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new Form1Panel(arg0,CategoryProductPage.class);
			}
		});
		
	}
	
	private void renderBigGridProductPic() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_pic_grid") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new GridBigPicPanel(arg0, "推荐商品", SystemConfig.PRODUCT_TYPE_MAP.get("推荐商品"),Page1.class);
			}
		});
	}

	private void renderGridPic() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_gridpic") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new GridSmallPicPanel(arg0, "推荐品牌",Arrays.asList("fewf","fewfae","fwef","feowi"));
			}
		});
	}

	private void renderRank() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_rank") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new RankPanel(arg0, "销售排行", Page1.class);
			}
		});
	}

	private void renderTimeoutProduct() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_pic_timeout_list") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new HorizontalListPicProductInTabPanel(arg0, SystemConfig.PRODUCT_TYPE_MAP.get("限时抢购"),"限时抢购", SingleProductPage.class);
			}
		});
	}

	private void renderRecommentProduct() {
		// TODO Auto-generated method stub
		add(new AjaxLazyLoadPanel("wk_pic_recomment_list") {
			
			@Override
			public Component getLazyLoadComponent(String arg0) {
				// TODO Auto-generated method stub
				return new GridBigPicPanel(arg0,"新品上架",SystemConfig.PRODUCT_TYPE_MAP.get("新品上架"),HomePage.class);
			}
		});
	}

	private void renderDiscount1() {
		// TODO Auto-generated method stub
		//add(new Discount1Panel("wk_discount1","店长推荐",SingleProductPage.class));
	}

	private void renderInfoReport() {
		// TODO Auto-generated method stub
		add(new Info1Panel("wk_info_report",PassagePage.class));
	}

	private void renderCarousel() {
		// TODO Auto-generated method stub
		add(new Slide1Panel("wk_carousel",1,Page1.class));
	}

	private void renderPicList() {
		// TODO Auto-generated method stub
		add(new HorizontalList4PicProductPanel("wk_pic_4list",5,SingleProductPage.class));
	}

	private void renderSortNav() {
		// TODO Auto-generated method stub
		
		add(new Sortnav2Panel("wk_sort_nav",CategoryProductPage.class));
	}

	//渲染导航
	private void renderNav() {
		// TODO Auto-generated method stub

		//add(new Nav1Panel("wk_main_nav",new SystemConfig().getNav1Parameters()));
		add(new JdNavPanel("wk_main_nav", SystemConfig.getNavParameters()));
	}
	
	@Override
	public void renderHead(IHeaderResponse response) {
		// TODO Auto-generated method stub
		super.renderHead(response);
		
		response.render(CssHeaderItem.forReference(new CssResourceReference(CSSLocation.class,"web.css")));
	}
}
